<?php
/**
 * @orm tablename gridpersons
 */
class GridPerson extends DomArObject {
	
	/**
	 * @orm char(30)
	 */
	public $firstname;
	/**
	 * @orm char(30)
	 */
	public $lastname;
	/**
	 * @orm int(11)
	 */
	public $age;
	/**
	 * @orm float(6,2)
	 */
	public $money;
	/** 
	 * @orm float(6,2)
	 */ 
	public $spent;
	/**
	 * @orm char(30)
	 */
	public $group;
	/**
	 * @orm plugin SimpleOrder(group)
	 */
	public $order;
	
	
	public function randomize() {
		$names = array('Mari','Kalle','Oliver','Getter','Mihkel','Uku','Meelis','Peeter');
		$names2 = array('Savi','Kivi','Puu','Mägi','Küla','Linn','Tamm');
		
		$this->firstname = $names[array_rand( $names )];
		$this->lastname = $names2[array_rand( $names2 )];
		$this->age = mt_rand(18,40);
		$this->money = mt_rand(100,2000);
		$this->spent = mt_rand(0, $this->money );

		$groups = array('I','II','III');
		$this->group = $groups[array_rand($groups)];
	}
	
	public function createSampleData() {
		
		GridPerson::getTable()->update();
		
		$g = GridPerson::load(1);
		if( !$g ) {
			DomSql::query('TRUNCATE gridpersons;');
			for( $i=0; $i<80; $i++ ) {
				$p = new GridPerson();
				$p->randomize();
				$p->save();
			}
		}
		
	}
	
}
?>